package org.ii.infrastructure.flow.conversion;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.binding.convert.converters.Converter;
import org.springframework.binding.convert.service.DefaultConversionService;
import org.springframework.stereotype.Component;

/**
 * Beans of type {@link Converter} having this annotation on the class will automatically be added as converters if
 * {@link ConversionService} is used as the conversion service for Spring Webflow.
 */
// TODO rune.forberg is it possible to throw an exception if this annotation is added to a class not implementing the Converter interface?
@Component
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ConverterComponent {
	/**
	 * The value may indicate a suggestion for a logical component name, to be turned into a Spring bean in case of an
	 * autodetected component.
	 * 
	 * @return the suggested component name, if any
	 */
	String value() default "";

	/**
	 * If you specify a non blank value the annotated {@link Converter} will be added as a custom converter using
	 * {@link DefaultConversionService#addConverter(String, Converter)}.<br/>
	 * If you don't specify a value the annotated {@link Converter} will be added as a default converter using
	 * {@link DefaultConversionService#addConverter(Converter)}.
	 */
	String converterId() default "";
}
